import request from '@/utils/request'
import {requestType} from '@/type/data'
import {AxiosRequestConfig} from 'axios'
/**
 * @description GET
 */
const GET = (data: requestType) => {
  return request.get(data.url, data.params)
}

/**
 * @description POST
 */
const POST = (data: requestType) => {
  return request.post(data.url, data.params)
}
/**
 * @description PUT
 */
const PUT = (data: requestType) => {
  return request.put(data.url, data.params)
}

/**
 * @description DELETE
 */
const DELETE = (data: requestType) => {
  return request({
    url: data.url,
    method: 'delete',
    data: data.params,
  } as AxiosRequestConfig)
}

/**
 * @description PATCH
 */
const PATCH = (data: requestType) => {
  return new Promise((resolve, reject) => {
    request
      .put(data.url, data.params)
      .then((res: any) => {
        if (res && res.status == 200) {
          resolve(res)
        }
      })
      .catch((error: any) => {
        reject(error)
      })
  })
}
export { GET, POST, PUT, DELETE, PATCH }